package com.lizardmind.haofudoctor.ui.studio.visit

import android.os.Bundle
import android.support.constraint.ConstraintLayout
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.View
import android.widget.LinearLayout
import com.linxiao.framework.activity.BaseActivity
import com.linxiao.framework.adapter.BaseAdapter
import com.linxiao.framework.adapter.DividerGridItemDecoration
import com.linxiao.framework.util.color
import com.lizardmind.haofudoctor.R
import com.lizardmind.haofudoctor.databinding.ItemHistoryDiagnoseBinding
import com.lizardmind.haofudoctor.databinding.ItemHistoryVisitBinding
import com.lizardmind.haofudoctor.manager.postApi
import com.lizardmind.haofudoctor.other.*
import com.lizardmind.haofudoctor.ui.diagnosis.diagnose.LookDiagnoseActivity
import kotlinx.android.synthetic.main.include_title_text.*
import org.jetbrains.anko.include
import org.jetbrains.anko.linearLayout
import org.jetbrains.anko.sdk25.coroutines.onClick
import org.jetbrains.anko.toast

/**
 *
 * Created by Extends on 2017/11/24 15:46
 */
class HistoryVisitActivity : BaseActivity() {
    private val apt by lazy { BaseAdapter<VisitBean, ItemHistoryVisitBinding>(R.layout.item_history_visit, type) }
    private val type by lazy { (intent.getSerializableExtra("ser") as SerializableBean).ser as ArrayList<VisitBean> }
    private lateinit var rv: RecyclerView
    override fun onCreatRootView(): View {
        return linearLayout {
            orientation = LinearLayout.VERTICAL
            include<ConstraintLayout>(R.layout.include_title_text)
            rv = recyclerView {
                id = R.id.test_recycler
                layoutManager = LinearLayoutManager(context)
                adapter =apt
                addItemDecoration(DividerGridItemDecoration(context, 2f, context.color(R.color.windowBackground)))
            }.lparams(-1,-1)
        }
    }

    override fun onInitView(savedInstanceState: Bundle?) {

        //初始化title
        imgLeft.setImageResource(R.mipmap.back)
        imgLeft.onClick { finish() }
        titleText.text = "随访复诊单"

        apt.onBind { itemBingding, position, data ->
            itemBingding.root.onClick {
                if(data.documents_status==0){
                    toast("当前复诊单尚未被填写")
                }else{
//                    startActivity<LookDiagnoseActivity>("id" to data.id)
                }
            }
        }
    }
}